home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Kant Generator Pro 1.0.1 / source / Mercutio API / Mercutio API.p < prev   
Encoding:
Text File  |  1994-10-30  |  5.6 KB  |  187 lines  |  [TEXT/PJMM]

  1. UNIT MercutioAPI;
  2.  
  3.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  4.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  5.     {xxx}
  6.     {xxx     Developer's Programming Interface for Mercutio Menu Definition Function}
  7.     {xxx            ©1992 Ramon M. Felciano, All Rights Reserved}
  8.     {xxx}
  9.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  10.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  11.  
  12. INTERFACE
  13.  
  14.     FUNCTION PowerMenuKey (theMessage: longint; theModifiers: integer; hMenu: menuHandle): longint;
  15.  
  16.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  17.     {x}
  18.     {x    PowerMenuKey is a replacement for the standard toolbox call MenuKey for use with the}
  19.     {x    Mercutio. Given the keypress message and modifiers parameters from a standard event, it }
  20.     {x    checks to see if the keypress is a key-equivalent for a particular menuitem. If you are currently}
  21.     {x    using custom menus (i.e. menus using Mercutio), pass the handle to one of these menus in}
  22.     {x    hMenu. If you are not using custom menus, pass in NIL or another menu, and PowerMenuKey will use the}
  23.     {x    standard MenuKey function to interpret the keypress.}
  24.     {x}
  25.     {x    As with MenuKey, PowerMenuKey returns the menu ID in high word of the result, and the menu}
  26.     {x    item in the low word.}
  27.     {x}
  28.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  29.  
  30.  
  31.     FUNCTION GetMDEFCopyright (menu: MenuHandle): str255;
  32.     FUNCTION GetMDEFVersion (menu: MenuHandle): longint;
  33.  
  34.  
  35.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  36.     {x}
  37.     {x    These routines allow you to retrieve the Copyright and Version information}
  38.     {x    embedded within the MDEF. The Version information is returned as a longint,}
  39.     {x    which can be typecast to a normal version resource.}
  40.     {x}
  41.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. IMPLEMENTATION
  49.     CONST
  50.         customDefProcSig = 'CUST';
  51.         areYouCustomMsg = 128;
  52.         getVersionMsg = 131;
  53.         getCopyrightMsg = 132;
  54.         mMenuKeyMsg = 262;
  55.  
  56.     TYPE
  57.     {* MENU resource structures *}
  58.         stdItemData = PACKED RECORD
  59.                 iconID: byte;
  60.                 keyEq: char;
  61.                 mark: char;
  62.                 textStyle: style;
  63.             END;
  64.         StdItemDataPtr = ^stdItemData;
  65.  
  66.     {* Menubar structures *}
  67.         MBarRec = PACKED RECORD
  68.                 offsetToLastMenu: integer;
  69.                 HorizRtEdgeLastMenu: integer;
  70.                 dummy: integer;
  71.                 menuIDList: ARRAY[1..100] OF PACKED RECORD
  72.                         theMenu: menuhandle;
  73.                         HorizRtEdge: integer;
  74.                     END;
  75.             END;
  76.         MBarRecPtr = ^MBarRec;
  77.  
  78.     {* MenuKey result structure *}
  79.         menuMatch = PACKED RECORD            { to get around pascal's typing    }
  80.                 CASE boolean OF
  81.                     true: (
  82.                             L: LongInt;
  83.                     );
  84.                     false: (
  85.                             menuID, itemNum: integer;
  86.                     );
  87.             END;
  88.  
  89.  
  90.  
  91.  
  92.     PROCEDURE CallMDEF (message: integer; theMenu: MenuHandle; VAR menuRect: Rect; hitPt: Point; VAR whichItem: integer; defProc: ProcPtr);
  93.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  94.     {x    Simple inline assembly code to call an MDEF, courtesy of John Cavallino. }
  95.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  96.     INLINE
  97.         $205F,    { move.l (SP)+,A0 }
  98.         $4E90;    { jsr (A0) }
  99.  
  100.  
  101.  
  102.     FUNCTION IsCustomMenu (menu: MenuHandle): boolean;
  103.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  104.     {x}
  105.     {x    IsCustomMenu returns true if hMenu is controlled by a custom MDEF. This relies on my}
  106.     {x    convention of returning the customDefProcSig constant in the rect parameter: this obtuse}
  107.     {x    convention should be unique enough that only my custom MDEFs behave this way.}
  108.     {x}
  109.     {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
  110.         VAR
  111.             state: SignedByte;
  112.             proc: handle;
  113.             dummy: rect;
  114.             dummyInt: integer;
  115.     BEGIN
  116.         proc := menu^^.menuProc;
  117.         state := HGetState(proc);
  118.         HLock(proc);
  119.         dummy.topLeft := point(longint(0));
  120.         CallMDEF(areYouCustomMsg, menu, dummy, point(longint(0)), dummyInt, proc^);
  121.         HSetState(proc, state);
  122.         IsCustomMenu := longint(dummy.topLeft) = longint(customDefProcSig);
  123.     END;
  124.  
  125.  
  126.  
  127.     FUNCTION GetMDEFVersion (menu: MenuHandle): longint;
  128.         VAR
  129.             state: SignedByte;
  130.             proc: handle;
  131.             dummy: rect;
  132.             dummyInt: integer;
  133.     BEGIN
  134.         proc := menu^^.menuProc;
  135.         state := HGetState(proc);
  136.         HLock(proc);
  137.         dummy.topLeft := point(longint(0));
  138.         CallMDEF(getVersionMsg, menu, dummy, point(longint(0)), dummyInt, proc^);
  139.         HSetState(proc, state);
  140.         GetMDEFVersion := longint(dummy.topLeft);
  141.     END;
  142.  
  143.     FUNCTION GetMDEFCopyright (menu: MenuHandle): str255;
  144.         VAR
  145.             state: SignedByte;
  146.             proc: handle;
  147.             dummy: rect;
  148.             dummyInt: integer;
  149.             hCopyright: stringHandle;
  150.     BEGIN
  151.         GetMDEFCopyright := '';
  152.         proc := menu^^.menuProc;
  153.         state := HGetState(proc);
  154.         HLock(proc);
  155.         dummy.topLeft := point(longint(0));
  156.         CallMDEF(getCopyrightMsg, menu, dummy, point(longint(0)), dummyInt, proc^);
  157.         HSetState(proc, state);
  158.         hCopyright := stringHandle(dummy.topLeft);
  159.         IF hCopyright <> NIL THEN
  160.             GetMDEFCopyright := hCopyright^^;
  161.         disposeHandle(handle(hCopyright));
  162.     END;
  163.  
  164.  
  165.  
  166.     FUNCTION PowerMenuKey (theMessage: longint; theModifiers: integer; hMenu: menuHandle): longint;
  167.         VAR
  168.             state: SignedByte;
  169.             proc: handle;
  170.             dummyRect: rect;
  171.             dummyInt: integer;
  172.     BEGIN
  173.         IF ((hMenu = NIL) | (NOT IsCustomMenu(hMenu))) THEN
  174.             PowerMenuKey := MenuKey(char(bitAnd(theMessage, charcodemask)))
  175.         ELSE
  176.             BEGIN
  177.                 proc := hMenu^^.menuProc;
  178.                 state := HGetState(proc);
  179.                 HLock(proc);
  180.                 dummyRect.topLeft := point(longint(0));
  181.                 CallMDEF(mMenuKeyMsg, hMenu, dummyRect, point(theMessage), themodifiers, proc^);
  182.                 HSetState(proc, state);
  183.                 PowerMenuKey := longint(dummyRect.topleft);
  184.             END;
  185.     END;
  186.  
  187. END.